﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.SqlServer;

namespace BookShopWeb.Models.DB
{
    public partial class BookShopContext : DbContext
    {
        public BookShopContext()
        {
        }

        public BookShopContext(DbContextOptions<BookShopContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Book> Books { get; set; }
        public virtual DbSet<CategoryesBook> CategoryesBooks { get; set; }
        public virtual DbSet<CategoryesStationery> CategoryesStationeries { get; set; }
        public virtual DbSet<FeedbackBook> FeedbackBooks { get; set; }
        public virtual DbSet<Order> Orders { get; set; }
        public virtual DbSet<PublishersBook> PublishersBooks { get; set; }
        public virtual DbSet<Shop> Shops { get; set; }
        public virtual DbSet<Stationery> Stationerys { get; set; } 
        public virtual DbSet<StationerysFeedback> StationerysFeedbacks { get; set; }
        public virtual DbSet<TypeCoversBook> TypeCoversBooks { get; set; } 
        public virtual DbSet<Users> Users { get; set; } 
        public virtual DbSet<UsersBascet> UsersBascets { get; set; } 
        public virtual DbSet<WritersBook> WritersBooks { get; set; }
        public virtual DbSet<NewBooks> NewBooks { get; set; }
        public virtual DbSet<SalesHitsBooks> SalesHitsBooks { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {                optionsBuilder.UseSqlServer("Data Source=(localdb)\\mssqllocaldb;Initial Catalog=BookShop;Integrated Security=True");
            }
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<SalesHitsBooks>(entity =>
            {
                entity.Property(e => e.BookID).HasColumnName("BookID");
                entity.Property(e => e.Title).HasColumnName("Title");
                entity.Property(e => e.Name).HasColumnName("Name");
                entity.Property(e => e.Price).HasColumnName("Price");
                entity.Property(e => e.Photo).HasColumnName("Photo");
                entity.Property(e => e.Discount).HasColumnName("Discount");
            });
            modelBuilder.Entity<NewBooks>(entity =>
            {
                entity.Property(e => e.Title).HasColumnName("Title");
                entity.Property(e => e.Name).HasColumnName("Name");
                entity.Property(e => e.Price).HasColumnName("Price");
                entity.Property(e => e.Discount).HasColumnName("Discount");
                entity.Property(e => e.Photo).HasColumnName("Photo");
            });
            modelBuilder.Entity<Book>(entity =>
            {
                entity.Property(e => e.BookId).HasColumnName("BookID");

                entity.Property(e => e.CategoryId).HasColumnName("CategoryID");

                entity.Property(e => e.DateAdd).HasColumnType("datetime");

                entity.Property(e => e.Description).HasMaxLength(200);

                entity.Property(e => e.Photo).HasMaxLength(150);

                entity.Property(e => e.PublisherId).HasColumnName("PublisherID");

                entity.Property(e => e.Title).HasMaxLength(50);

                entity.Property(e => e.TypeCoverId).HasColumnName("TypeCoverID");

                entity.Property(e => e.WriterID).HasColumnName("WriterID");

                entity.Property(e => e.CountSales).HasColumnName("CountSales");
            });

            modelBuilder.Entity<CategoryesBook>(entity =>
            {
                entity.HasKey(e => e.CategoryId);

                entity.Property(e => e.CategoryId).HasColumnName("CategoryID");

                entity.Property(e => e.Name).HasMaxLength(50);
            });

            modelBuilder.Entity<CategoryesStationery>(entity =>
            {
                entity.HasKey(e => e.CategoryId);

                entity.ToTable("CategoryesStationery");

                entity.Property(e => e.CategoryId).HasColumnName("CategoryID");

                entity.Property(e => e.Name).HasMaxLength(50);
            });

            modelBuilder.Entity<FeedbackBook>(entity =>
            {
                entity.HasKey(e => e.FeedbackId);

                entity.Property(e => e.FeedbackId).HasColumnName("FeedbackID");

                entity.Property(e => e.BookId).HasColumnName("BookID");

                entity.Property(e => e.Date).HasColumnType("datetime");

                entity.Property(e => e.Title).HasMaxLength(50);
            });

            modelBuilder.Entity<Order>(entity =>
            {
                entity.Property(e => e.OrderId)
                    .ValueGeneratedNever()
                    .HasColumnName("OrderID");

                entity.Property(e => e.DateOrder).HasColumnType("datetime");

                entity.Property(e => e.UserId)
                    .ValueGeneratedOnAdd()
                    .HasColumnName("UserID");
            });

            modelBuilder.Entity<PublishersBook>(entity =>
            {
                entity.HasKey(e => e.PublisherId);

                entity.Property(e => e.PublisherId).HasColumnName("PublisherID");

                entity.Property(e => e.Name).HasMaxLength(50);
            });

            modelBuilder.Entity<Shop>(entity =>
            {
                entity.Property(e => e.ShopId).HasColumnName("ShopID");
            });

            modelBuilder.Entity<Stationery>(entity =>
            {
                entity.HasNoKey();

                entity.Property(e => e.DateAdd).HasColumnType("datetime");

                entity.Property(e => e.Size).HasMaxLength(50);

                entity.Property(e => e.StationerysId)
                    .ValueGeneratedOnAdd()
                    .HasColumnName("StationerysID");

                entity.Property(e => e.Title).HasMaxLength(50);
            });

            modelBuilder.Entity<StationerysFeedback>(entity =>
            {
                entity.HasKey(e => e.FeedbackId)
                    .HasName("PK_StationeryFeedback");

                entity.ToTable("StationerysFeedback");

                entity.Property(e => e.FeedbackId).HasColumnName("FeedbackID");

                entity.Property(e => e.Date)
                    .HasMaxLength(10)
                    .IsFixedLength();

                entity.Property(e => e.StationeryId).HasColumnName("StationeryID");

                entity.Property(e => e.Title).HasMaxLength(50);
            });

            modelBuilder.Entity<TypeCoversBook>(entity =>
            {
                entity.HasKey(e => e.TypeCoverId);

                entity.ToTable("TypeCoversBook");

                entity.Property(e => e.TypeCoverId).HasColumnName("TypeCoverID");

                entity.Property(e => e.Name).HasMaxLength(50);
            });

            modelBuilder.Entity<Users>(entity =>
            {
                entity.Property(e => e.UserId).HasColumnName("UserID");

                entity.Property(e => e.Email).HasMaxLength(50);

                entity.Property(e => e.Login).HasMaxLength(50);

                entity.Property(e => e.Name).HasMaxLength(50);

                entity.Property(e => e.Password).HasMaxLength(150);

                entity.Property(e => e.Patronymic).HasMaxLength(50);

                entity.Property(e => e.Phone).HasMaxLength(20);

                entity.Property(e => e.Surname).HasMaxLength(50);
            });

            modelBuilder.Entity<UsersBascet>(entity =>
            {
                entity.HasKey(e => e.BascetId);

                entity.Property(e => e.Category).HasMaxLength(50);

                entity.Property(e => e.ProductId).HasColumnName("ProductID");
            });

            modelBuilder.Entity<WritersBook>(entity =>
            {
                entity.HasKey(e => e.WriterId);
                entity.Property(e => e.Name).HasMaxLength(50);
            });

          
            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
